import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

export default defineConfig({
	main: {
		plugins: [externalizeDepsPlugin()]
	},
	preload: {
		plugins: [externalizeDepsPlugin()]
	},
	renderer: {
		resolve: {
			alias: {
				'@@': resolve('src/renderer/src')
			}
		},
		// 插件配置
		plugins: [
			vue(),
			AutoImport({
				include: [
					/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
					/\.vue$/,
					/\.vue\?vue/ // .vue
				],
				// 哪些插件需要自动导入
				imports: ['vue', 'vue-router', 'pinia'],
				// 使用Eslint 需要配置enabled为true
				eslintrc: {
					enabled: true
				},
				// 需要自动导入的UI框架规则
				resolvers: [ElementPlusResolver()]
			}),
			Components({
				// 组件自动导入：组件文件所在位置
				dirs: ['src/renderer/src/components'],
				// 特质的文件后缀名
				extends: ['vue'],
				// 是否深度搜索
				deep: false,
				// 需要自动导入的UI框架规则
				resolvers: [ElementPlusResolver()]
			})
		]
	}
})
